%D \module
%D    [file=t-zhfonts,
%D     version=2009.08.01,
%D     title=\CONTEXT\ User Macros,
%D     subtitle=Font for simple Chinese users,
%D     author=Li Yanrui,
%D     date=\currentdate,
%D     copyright=Public Domain]

\writestatus{loading}{ConTeXt User Module / zhfonts}
\unprotect

%D 定义 latinfallback 字体
\def\latinfallbackarea{0x0000-0x0400}
\def\definelatinfallbackfont[#1]%
  {\definefontfallback[latin#1][\getvalue{latin#1}][\latinfallbackarea][force=yes]}

%D 定义中文字体，并将 latin 字体灌注到部分中文字符区域
\starttypescript[serif][zhfont]
  \definefontsynonym[Serif][\zhSerif][fallbacks=latinSerif]
  \definefontsynonym[SerifBold][\zhSerifBold][fallbacks=latinSerifBold]
  \definefontsynonym[SerifItalic][\zhSerifItalic][fallbacks=latinSerifItalic]
  \definefontsynonym[SerifBoldItalic][\zhSerifBoldItalic][fallbacks=latinSerifBoldItalic]
\stoptypescript

\starttypescript[sans][zhfont]
  \definefontsynonym[Sans][\zhSans][fallbacks=latinSans]
  \definefontsynonym[SansBold][\zhSansBold][fallbacks=latinSansBold]
  \definefontsynonym[SansItalic][\zhSansItalic][fallbacks=latinSansItalic]
  \definefontsynonym[SansBoldItalic][\zhSansBoldItalic][fallbacks=latinSansBoldItalic]
\stoptypescript

\starttypescript[mono][zhfont]
  \definefontsynonym[Mono][\zhMono][fallbacks=latinMono]
  \definefontsynonym[MonoBold][\zhMonoBold][fallbacks=latinMonoBold]
  \definefontsynonym[MonoItalic][\zhMonoItalic][fallbacks=latinMonoItalic]
  \definefontsynonym[MonoBoldItalic][\zhMonoBoldItalic][fallbacks=latinMonoBoldItalic]
\stoptypescript

%D 定义字样
\starttypescript[zhfonts]
  \definetypeface[zhfonts][rm][serif][zhfont][default]
  \definetypeface[zhfonts][ss][sans][zhfont][default]
  \definetypeface[zhfonts][tt][mono][zhfont][default]
\stoptypescript

%D 字体定义命令
\def\setupzhfonts
  {\dotripleargument\dosetupzhfonts}

\def\dosetupzhfonts[#1][#2][#3]%
  {\setvalue{zh#1}{name:#2}%
   \setvalue{latin#1}{name:#3}%
   \definelatinfallbackfont[#1]}

\setupzhfonts[Serif][AdobeSongStd-Light][TeXGyrePagella-Regular]
\setupzhfonts[SerifBold][AdobeSongStd-Light][TeXGyrePagella-Bold]
\setupzhfonts[SerifItalic][AdobeSongStd-Light][TeXGyrePagella-Italic]
\setupzhfonts[SerifBoldItalic][AdobeSongStd-Light][TeXGyrePagella-BoldItalic]

\setupzhfonts[Sans][AdobeSongStd-Light][TeXGyreHeros-Regular]
\setupzhfonts[SansBold][AdobeSongStd-Light][TeXGyreHeros-Bold]
\setupzhfonts[SansItalic][AdobeSongStd-Light][TeXGyreHeros-Italic]
\setupzhfonts[SansBoldItalic][AdobeSongStd-Light][TeXGyreHeros-BoldItalic]

\setupzhfonts[Mono][AdobeSongStd-Light][TeXGyreCursor-Regular]
\setupzhfonts[MonoBold][AdobeSongStd-Light][TeXGyreCursor-Bold]
\setupzhfonts[MonoItalic][AdobeSongStd-Light][TeXGyreCursor-Italic]
\setupzhfonts[MonoBoldItalic][AdobeSongStd-Light][TeXGyreCursor-BoldItalic]

\usetypescript[zhfonts]%
\setscript[hanzi]

\protect
\endinput

